package com.t17;

import com.t11.ListIteration;

import java.util.*;

import static net.mindview.util.Print.print;

/**
 * Created by xuyiwei on 2018/8/26.
 */
public class ReadOnly {
    static Collection<String> data = new ArrayList<String>(Countries.names(6));
    public static void main(String[] args) {
        Collection<String> c = Collections.unmodifiableCollection(data);
        print(c);
        //这个map是只读，装载数据后，就应该使用不可修改的方法返回的引用去替换掉原本的引用
        //c.add("one");
        List<String> a = Collections.unmodifiableList(new ArrayList<>(data));
        ListIterator<String> lit = a.listIterator();
        print(lit.next());
        //这个map是只读，装载数据后，就应该使用不可修改的方法返回的引用去替换掉原本的引用
        //lit.add("one");
        Set<String> s = Collections.unmodifiableSet(new HashSet<String>(data));
        //s.add("one");
        Set<String> ss = Collections.unmodifiableSortedSet(new TreeSet<String>(data));
        Map<String,String> m = Collections.unmodifiableMap(new HashMap<String,String>(Countries.capitals(5)));
        print(m);
        m.put("Ralph","Howdy!");
        Map<String,String> sm = Collections.unmodifiableSortedMap(new TreeMap<>(Countries.capitals(5)));
    }
}
